home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / hf^k-6.dms / in.adf / Install.run / GOLDEDDATA / developer / examples / scanner / source / struct.c < prev   
Encoding:
C/C++ Source or Header  |  1996-08-30  |  2.1 KB  |  88 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   COPYIGHT
  4.  
  5.   ©1995  Dietmar  Eilert  (e-mail:  DIETMAR@TOMATE.TNG.OCHE.DE).  All  Rights
  6.   Reserved.  Code  may not be reused/reproduced without written permission of
  7.   the author.
  8.  
  9.   Dietmar Eilert
  10.   Mies-v-d-Rohe-Str.31, 52074 Aachen, Germany
  11.   E-Mail: DIETMAR@TOMATE.TNG.OCHE.DE
  12.   Tel: +49-(0)241-81665
  13.        +49-(0)2525-7776
  14.   Fax: +49-(0)241-81665
  15.  
  16.   Example: scan handler looking for C strucures. Scan handlers are plain
  17.   functions (LoadSeg'ed by GED): no standard C startup code, no library calls.
  18.   
  19.   DICE-C:
  20.   
  21.   dcc struct.c -// -l0 -md -mRR -o ram:struct
  22.  
  23.   ------------------------------------------------------------------------------
  24. */
  25.  
  26. #include <exec/types.h>
  27.  
  28. #define UPPER(a) ((a) & 95)
  29.  
  30. ULONG
  31. ScanHandlerStruct(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
  32. {
  33.     const char *version = "$VER: Struct 1.0 (" __COMMODORE_DATE__ ")";
  34.  
  35.     UBYTE *from = *text;
  36.  
  37.     if (len > 8) {
  38.  
  39.         if ((from[0] == 't') && (from[1] == 'y') && (from[2] == 'p') && (from[3] == 'e') && (from[4] == 'd') && (from[5] == 'e') && (from[6] == 'f') && (from[7] == ' ')) {
  40.  
  41.             // ignore typedef keyword
  42.  
  43.             len  -= 8;
  44.             from += 8;
  45.         }
  46.     }
  47.  
  48.     if (len > 7) {
  49.  
  50.         if ((from[0] == 's') && (from[1] == 't') && (from[2] == 'r') && (from[3] == 'u') && (from[4] == 'c') && (from[5] == 't') && (from[6] == ' ')) {
  51.  
  52.             // found struct keyword
  53.  
  54.             UBYTE *last;
  55.  
  56.             for (last = from + len - 1; len && (*last == 32); --len)
  57.                 --last;
  58.  
  59.             from += 7;
  60.             len  -= 7;
  61.  
  62.             if ((*last != ',') && (*last != '*')) {
  63.  
  64.                 UWORD pos = len;
  65.  
  66.                 // check if there is a ';' in this line
  67.  
  68.                 while (pos--)
  69.                     if (from[pos] == ';')
  70.                         return(FALSE);
  71.  
  72.                 if (*from != '{') {
  73.  
  74.                     *text = from;
  75.  
  76.                     for (len = 0; (from <= last) && (*from >= 48); ++len)
  77.                         ++from;
  78.  
  79.                     return(len);
  80.                 }
  81.             }
  82.         }
  83.     }
  84.  
  85.     return(FALSE);
  86. }
  87.  
  88.